#include"get_x_y.h"

/************************************ 
 *函数功能： 获取X Y坐标值
 *函数名：int get_xy(void)
 *参数：void
 *返回值：int (x,y)坐标值 
*************************************/
int get_xy(void)
{
    struct input_event ts;

    ts_fd = open(TS_PATH, O_RDWR);
    if(ts_fd == -1)
    {
        printf("open ts failure\n");
        return -1;
    }

    while(1)
    {
        //松开触摸后，再打印
        while (1)
        {
            read(ts_fd, &ts, sizeof(struct input_event));

            //判断类型
            if(ts.type == EV_ABS && ts.code == ABS_X)
            {
                X = ts.value;
            }

            if(ts.type == EV_ABS && ts.code == ABS_Y)
            {
                Y = ts.value;
            }

            //判断按下
            if(ts.type == EV_KEY && ts.code ==  BTN_TOUCH && ts.value == 1){ }
           
            //判断是否松开
            if(ts.type == EV_KEY && ts.code ==  BTN_TOUCH && ts.value == 0)
            {                                                  	             	
                X = X*(800.0/1024.0);      
                Y = Y*(480.0/600.0);
                break;
            }           
        }
        printf("X:%d, Y:%d\n", X, Y);
        return 0;
    }
}
